<template>
    <div>
        <Modal v-model="modalSs11008" :title=title width="750" cancel-text="关闭" style="position:relative;">
            <Form :disabled="disableSubmit01" ref="dataSs11008" :model="dataSs11008" :rules="ruleSs11008" inline :label-width="130">
                <table style="width:100%;">
                    <tr>
                        <td style="width:50%;">
                            <FormItem label="人员姓名" prop="ssbf0001">
                                <dictSelect :sel_val='dataSs11008.ssbf0001' dicType="service" :bindData.sync="dataSs11008.ssbf0001"  :serviceParam="serviceParam"
                                            dictService="/api/ac/subsistence/ss17002Service/getAssistanceMemberList" class="itemStyle"   />
                            </FormItem>
                        </td>
                        <td style="width:50%;">
                            <FormItem label="组织机构代码" prop="ssbf0002">
                                <Input v-model="dataSs11008.ssbf0002" placeholder=""  class="itemStyle"   />
                            </FormItem>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <FormItem label="单位名称" prop="ssbf0003">
                                <Input v-model="dataSs11008.ssbf0003" placeholder=""  class="itemStyle"   />
                            </FormItem>
                        </td>
                        <td>
                            <FormItem label="单位地址" prop="ssbf0006">
                                <Input v-model="dataSs11008.ssbf0006" placeholder=""  class="itemStyle"   />
                            </FormItem>
                        </td>

                    </tr>
                    <tr>
                        <td>
                            <FormItem label="单位性质" prop="ssbf0004">
                                <dictSelect :sel_val='dataSs11008.ssbf0004' :bindData.sync="dataSs11008.ssbf0004" dictCode="companynature"  class="itemStyle"   />
                            </FormItem>
                        </td>
                        <td>
                            <FormItem label="单位隶属" prop="ssbf0005">
                                <dictSelect :sel_val='dataSs11008.ssbf0005' :bindData.sync="dataSs11008.ssbf0005" dictCode="companyaffiliation"  class="itemStyle"   />
                            </FormItem>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <FormItem label="联系电话" prop="ssbf0007">
                                <Input v-model="dataSs11008.ssbf0007" placeholder=""  class="itemStyle"   />
                            </FormItem>
                        </td>
                        <td>
                            <FormItem label="入职时间" prop="ssbf0008">
                                <DatePicker type="date" v-model="dataSs11008.ssbf0008" placeholder="" class="itemStyle"    />
                            </FormItem>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <FormItem label="离职时间" prop="ssbf0009">
                                <DatePicker type="date" v-model="dataSs11008.ssbf0009" placeholder="" class="itemStyle"    />
                            </FormItem>
                        </td>
                        <td>
                            <FormItem label="所在部门" prop="ssbf0010">
                                <Input v-model="dataSs11008.ssbf0010" placeholder=""  class="itemStyle"   />
                            </FormItem>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <FormItem label="职业" prop="ssbf0011">
                                <Input v-model="dataSs11008.ssbf0011" placeholder=""  class="itemStyle"   />
                            </FormItem>
                        </td>
                        <td>
                            <FormItem label="岗位" prop="ssbf0012">
                                <Input v-model="dataSs11008.ssbf0012" placeholder=""  class="itemStyle"    />
                            </FormItem>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <FormItem label="工龄" prop="ssbf0013">
                                <Input v-model="dataSs11008.ssbf0013" placeholder=""  class="itemStyle" number   />
                            </FormItem>
                        </td>
                        <td>
                            <FormItem label="薪水" prop="ssbf0014">
                                <Input v-model="dataSs11008.ssbf0014" placeholder=""  class="itemStyle" number   />
                            </FormItem>
                        </td>
                    </tr>
                    <tr>
                        <td colspan="2">
                            <FormItem label="备注" prop="ssbf0015">
                                <Input type="textarea" :rows="2" v-model="dataSs11008.ssbf0015" placeholder="" style="width:540px"   />
                            </FormItem>
                        </td>
                    </tr>
                </table>
            </Form>
            <div slot="footer">
                <Button type="text" size="large" @click="modalSs11008 = false">关闭</Button>
            </div>
        </Modal>
        <div style="margin-top: 10px">
            <Table :columns="columns" :data="tableData" :loading="Loading" border>
                <template slot-scope="{ row, index}" slot="action">
                    <Button type="info" size="small" style="margin-right: 5px" @click="handleEdit(index)">详情</Button>
                </template>
            </Table>
            <div style="margin: 10px;overflow: hidden">
                <div style="float: right;">
                    <Page :total="dataCount" :page-size="pageSize" show-total class="paging"
                          @on-change="handleTableChange" :current="pageNo"></Page>
                </div>
            </div>
        </div>
    </div>
</template>
<script>
    import {CommonMixin} from '@/views/common/js/CommonMixin'
    import dictSelect from '@/components/dictSelect/dictSelect.vue'
    import {postAction} from '@/api/request'
    import DateFormat from '@/plugins/format.js'

    export default {
        components: { dictSelect },
        mixins: [CommonMixin],
        data () {
            return {
                disableSubmit01: true,
                serviceParam:{
                    azcp0500:''
                },
                modalSs11008:false,
                columns: [
                    {
                        title: '人员姓名',
                        align: 'center',
                        key: 'ssbf0001_name',
                    },
                    {
                        title: '单位名称',
                        align: 'center',
                        key: 'ssbf0003',
                    },
                    {
                        title: '单位地址',
                        align: 'center',
                        key: 'ssbf0006',
                    },
                    {
                        title: '所在部门',
                        align: 'center',
                        key: 'ssbf0010',
                    },
                    {
                        title: '职业',
                        align: 'center',
                        key: 'ssbf0011',
                    },
                    {
                        title: '岗位',
                        align: 'center',
                        key: 'ssbf0012',
                    },
                    {
                        title: '操作',
                        slot: 'action',
                        align:'center',
                        width:200,
                      fixed:'right'
                    }
                ],
                tableData: [],
                Loading: false,
                btnLoading:false,
                dataCount: 0,
                pageSize: 10,
                familyInfo: {},
                queryParam: {},
                ss11001Id: '',
                url: {
                    list: '/api/ac/subsistence/ss17008Service/getPageList',
                    delete: '/api/ac/subsistence/ss17008Service/deleteData',
                    insertSs11008:"/api/ac/subsistence/ss17008Service/createData",
                    updateSs11008:"/api/ac/subsistence/ss17008Service/updateData",
                },
                title:'',
                dataSs11008: {
                    id: '',
                    ssbf0001: '',
                    ssbf0003: '',
                    ssbf0004: '',
                    ssbf0005: '',
                    ssbf0006: '',
                    ssbf0007: '',
                    ssbf0008: null,
                    ssbf0009: null,
                    ssbf0010:'',
                    ssbf0011:'',
                    ssbf0012:'',
                    ssbf0013:0,
                    ssbf0014:0,
                    ssbf0015:'',
                },
                fieldsToValidate: ["ssbf0001","ssbf0003","ssbf0006","ssbf0013","ssbf0014"],
                ruleSs11008: {
                    ssbf0001: [
                        {required: true, message: '请选择人员', trigger: 'blur'}
                    ],
                    ssbf0003: [
                        {required: true, message: '填写单位名称', trigger: 'blur'}
                    ],
                    ssbf0006: [
                        {required: true, message: '填写单位地址', trigger: 'blur'}
                    ],
                    ssbf0013: [
                        {message: '请填写数字', trigger: 'blur',type:'number'}
                    ],
                    ssbf0014: [
                        {message: '请填写数字', trigger: 'blur',type:'number'}
                    ],
                },
            }
        },
        methods: {
            prevStep () {
                this.$parent.clickStep(6);
            },
            nextStep () {
                this.$parent.clickStep(8);
            },
            handleEdit (index) {
                let that=this;
                let record=that.tableData[index];
                if (record.id) {
                    that.edit(record)
                } else {
                    that.$Message.error('请选择操作数据');
                }
            },
            handleCreate () { // 录入
                let that=this;
                that.create()
            },
            handleDelete (index) {
                let that=this;
                let record=that.tableData[index];
                if (record.id) {
                    this.$Modal.confirm({
                        title: '确定删除吗',
                        onOk: () => {
                            let url=that.url.delete;
                            let dataParam={};
                            dataParam.id=record.id;
                            postAction(url, dataParam).then((res) => {
                                if(res.data.data.code==1) {
                                    that.$Message.success(res.data.data.msg);
                                    that.reloadData();
                                } else {
                                    that.$Message.error(res.data.data.msg);
                                }
                            });
                        },
                        onCancel: () => {
                        }
                    });

                } else {
                    that.$Message.error('请选择操作数据');
                }
            },
            handleView(){
                this.$Message.warning('功能开发中');
            },
            reloadData() {
                let that=this;
                that.queryParam.azcp0500=that.ss11001Id;
                that.loadData();
            },
            create(){
                let that=this;
                that.dataSs11008 = {}
                that.title="工作单位信息录入"
                that.modalSs11008 = true
            },
            edit(record){
                let that=this;
                that.title="工作单位信息编辑"
                that.modalSs11008 = true
                that.dataSs11008 = Object.assign({}, record);
                if(record.ssbf0008){
                    that.dataSs11008.ssbf0008=new Date(record.ssbf0008);
                }
                if(record.ssbf0009){
                    that.dataSs11008.ssbf0009=new Date(record.ssbf0009);
                }
            },
            handleSubmitSs11008 (name) {
                let that=this;
                let validate = true;
                let err_msg=[];
                for(let item of that.fieldsToValidate){
                    that.$refs[name].validateField(item, (error) => {
                        if (error) {
                            validate = false;
                            err_msg.push(error);
                        }
                    })
                }
                if (validate) {
                    let dataParam = {}
                    dataParam = Object.assign({}, that.dataSs11008)
                    let url=null;
                    if(dataParam.id==null){
                        url=that.url.insertSs11008
                    }else{
                        url=that.url.updateSs11008
                    }

                    postAction(url, dataParam).then((res) => {
                        if(res.data.data.code==1) {
                            that.modalSs11008 = false
                            that.$Message.success(res.data.data.msg)
                            that.reloadData();
                        } else {
                            that.$Message.error(res.data.data.msg);
                        }
                    }).finally(() => {

                    })
                }else{
                    that.$Message.error(err_msg[0]);
                    return;
                }
            },
        },
        mounted () {

        },
        created() {
            let that=this;
            that.familyInfo = that.$parent.familyInfo;
            that.ss11001Id=that.familyInfo.ssca0001;
            that.queryParam.azcp0500=that.familyInfo.ssca0001;
            this.loadData();

            that.serviceParam.azcp0500=that.familyInfo.ssca0001
        },
    }
</script>
<style scoped>
    /deep/.ivu-form-item-error-tip {
        display: none;
    }
    .ivu-form-item {
        margin-bottom: 0px;
    }
    .itemStyle{
        width:180px
    }
</style>
